package com.future.myjavatools.core.zhoupu;


import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @program: zp-crm
 * @description: rsa加密工具类
 * @author: lianweiq
 * @create: 2019-09-04 11:14
 */
public class MD5Cryptography {


    private static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbF2VznB2Xy9QOpTfQVfh6pUPjWuMJEkf4wugmXjAKLlv2RRKqPnBiSCy3qkaVE1AeburIXJSHgLE13ug2cxYvjgZWybDW1ZLCzesQnZA4VQByM23cm1SsRTbadcIC89YsqyScRRnQwANUDJttFaQ8EL9lvAtjYwe5u6dwIDAQAB";

    public static void main(String[] args) throws NoSuchAlgorithmException {
        System.out.println(buildFileName("test"));
    }

    public static String buildFileName(String fileName) throws NoSuchAlgorithmException {
        StringBuilder builder = new StringBuilder();

        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update((fileName + PUBLIC_KEY).getBytes(StandardCharsets.UTF_8));
        byte[] md5s = md5.digest();
        for (byte b : md5s) {
            builder.append(String.format("%02x", b & 0xff));
        }
        return builder.toString();
    }

}
